package com.controller;


import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.common.Result;
import com.common.log.OperationLog;
import com.common.log.OperationType;
import com.entity.JobLevel;
import com.entity.Leave;
import com.service.JobLevelService;
import com.service.LeaveService;
import com.service.sys.UserVoService;
import com.vo.sys.UserVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端发起请求，controller(跟前端进行数据交互) -> service(中间业务层) -> mapper(跟数据库进行增删改查)
 * </p>
 *
 * @author clay
 * @since 2022-03-27
 */
@RestController
@RequestMapping("/leave")
public class LeaveController {

    @Resource
    private LeaveService leaveService;

    @ApiOperation("添加请假")
    @OperationLog(operationType = OperationType.INSERT, describe = "添加请假", entity = Leave.class, primaryKey = "id")
    @PostMapping(value = "/add")
    public Result addDepartment(@RequestBody @Valid Leave leave) {
        leaveService.save(leave);
        return Result.success();
    }

    @ApiOperation("删除请假")
    @OperationLog(operationType = OperationType.DELETE, describe = "删除请假", entity = Leave.class, primaryKey = "id")
    @GetMapping(value = "/delete/{id}")
    public Result deleteDepartment(@PathVariable("id") String id) {
        leaveService.removeById(id);
        return Result.success();
    }

    @ApiOperation("通过id获取请假信息")
    @GetMapping(value = "/info/{id}")
    public Result info(@PathVariable("id") String id) {
        return Result.success(leaveService.getById(id));
    }

    @ApiOperation("查询请假信息")
    @PostMapping(value = "/select")
    public Result select(@RequestBody Leave leave) {
        return Result.success(leaveService.select(leave));
    }

    @ApiOperation("修改请假信息")
    @PostMapping("/update")
    @OperationLog(operationType = OperationType.UPDATE, describe = "修改请假信息", entity = Leave.class, primaryKey = "id")
    public Result update(@RequestBody Leave leave) {
        return Result.success(leaveService.updateById(leave));
    }

}
